package com.jinsi.service.impl;

import com.jinsi.mapper.ScStuMapper;
import com.jinsi.pojo.*;
import com.jinsi.service.ScStuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class ScStuServiceImpl implements ScStuService {
    @Autowired
    private ScStuMapper mapper;

    @Override
    public List<ScStudent> getStus() {
        List<ScStudent> list = mapper.getStus();
        return list;
    }

    @Override
    public List<ScStudent> getStusByLike(
            Integer studentId,
            String studentName,
            String studentIdNumber,
            String studentCreateDate
    ) {
        List<ScStudent> list = mapper.getStusByLike(
                studentId,
                studentName,
                studentIdNumber,
                studentCreateDate
        );
        return list;
    }

    @Override
    public List<ScStudentOperationLog> getStusByLikeIdAndName
            (Integer studentId, String studentName,Integer status) {
        List<ScStudentOperationLog> list = mapper.getStusByLikeIdAndName
                (studentId, studentName,status);
        return list;
    }


    //树级节点查询2
    @Override
    public List<Map<String,Object>> getStudentStandard(String studentId) {
        List<ScStudentStandard> studentStandards = mapper.getStudentStandard(studentId);
        ArrayList<Map<String,Object>> list  = new ArrayList<>();
        for (ScStudentStandard i: studentStandards) {
            Map<String,Object> map = new HashMap<>();
            map.put("id",i.getProjectId());
            map.put("title","单据分类："+i.getProjectId());
            List<ScStudentStandard> classDocumentSub = mapper.getStudentStandardSub(i.getProjectId());
            ArrayList<Map<String,Object>> subList  = new ArrayList<>();
            for (ScStudentStandard j: classDocumentSub) {
                Map<String,Object> subTreeData = new HashMap<>();
                subTreeData.put("id",j.getId());
                subTreeData.put("title",j.getProjectName());
                subList.add(subTreeData);
            }
            map.put("children",subList);
            list.add(map);
        }
        return list;
    }



    @Override
    public void delStu(String studentId) throws Exception {
        int num = mapper.delStu(studentId);
        if (num == 0){
            throw new Exception();
        }
    }


    @Override
    public void upStuByStatus(ScStudent student) throws Exception {
        int num = mapper.upStuByStatus(student);
        if (num == 0){
            throw new Exception();
        }
    }

    @Override
    public void save(List<ScStudent> cachedDataList) {
        mapper.save(cachedDataList);
    }

}
